package com.tcs.test.designmodel.observer;

import org.springframework.context.annotation.Bean;

/**
 * @ClassName : CurrentConditionsDisplay
 * @Author : 神经刀
 * @Date : 2019/5/28 : 22:56
 * @Version : 1.0
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement{

    private Subject subject;
    private float temp;
    private float humidity;
    private float pressure;

    public CurrentConditionsDisplay() {}

    public CurrentConditionsDisplay(Subject subject) {
        this.subject = subject;
        this.subject.registerObserver(this);
    }

    @Override
    public void display() {
        System.out.println(this.toString());
    }

    @Bean("")
    @Override
    public String toString() {
        return "CurrentConditionsDisplay{" +
                "subject=" + subject +
                ", temp=" + temp +
                ", humidity=" + humidity +
                ", pressure=" + pressure +
                '}';
    }

    @Override
    public void update(float temp, float humidity, float pressure) {
        this.temp = temp;
        this.humidity = humidity;
        this.pressure = pressure;
        this.display();
    }
}
